

package tables

import (
	"fmt"
	"game/game-design/loader"
	"strings"
	ministruct "sanguo/sanguo-design/src/ministruct"
)


var ModelTable *ModelTableStruct = &ModelTableStruct{}

type ModelTableStruct struct {
	loader.DesignTable[ModelCfg]
	
	idIndex map[string]*ModelCfg
	
	
	
}

func (t *ModelTableStruct) FileName() string {
	return "J角色与模型"
}

// 从索引中获取对象，获取不到会抛异常
func (t *ModelTableStruct) GetInIdIndex(
	id int32,
) *ModelCfg {
	key :=
		fmt.Sprint(id)
	
	cfg, ok := t.idIndex[key]
	if !ok {
		panic("ModelTable when GetInIdIndex use key not found " + key)
	}
	return cfg
}

// 从索引中查找对象，获取不到会返回null
func (t *ModelTableStruct) FindInIdIndex(
	id int32,
) (*ModelCfg, bool) {
	key :=
		fmt.Sprint(id)
	
	cfg, ok := t.idIndex[key]
	return cfg, ok
}

// 加载idIndex索引
func (t *ModelTableStruct) loadIdIndex() {
	idIndex := make(map[string]*ModelCfg)
	for _, v := range t.All() {
		keys := []string {
			fmt.Sprint(v.id),
		}
		key := strings.Join(keys, "_")
		_, exist := idIndex[key]
		if exist {
			fmt.Println(t.FileName(), " found duplicate key ", key, " in index ", "idIndex")
			continue
		}
		idIndex[key] = v
	}
	t.idIndex = idIndex
}



func (t *ModelTableStruct) LoadAutoGenerate() {
	//加载索引
	t.loadIdIndex()

	
}



type ModelCfg struct {
	id int32 //模型标识
}
// 模型标识
func (c *ModelCfg) GetId() int32 {
	return c.id
}

func ModelTableStructNoUse() {
	fmt.Println(ministruct.Cost{})
}
